/*
*  Impp - Instant Messenger
*
*  Copyright (C) 2008  Oliver Schneider
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#ifndef CHATPANEL_H_
#define CHATPANEL_H_

#include <wx/richtext/richtextctrl.h>
#include "ImppNotebook.h"
#include "ChatWindow.h"
#include "../StdUserInterfaceModule/AvatarArea.h"
#include "../../Main.h"
#include "../../core/Buddy.h"
#include "../../core/events/MessageEvent.h"
#include "../../core/events/MessageCallbackEvent.h"
#include "../../core/events/TypingNotificationEvent.h"
#include "../../core/events/StatusEvent.h"
#include "../../core/events/AvatarChangedEvent.h"
#include "../../core/events/FileTransfareEvent.h"
#include <wx/splitter.h>
#include <map>
#include "../StdUserInterfaceModule/interfaces/iChatLog.h"
#include "../StdUserInterfaceModule/ImppBitmapButton.h"


namespace Impp
{

class ChatWindow;

class ChatPanel : public wxPanel
{
public:
	enum{
		ID_LOG = wxID_HIGHEST,
		ID_INPUT,
		ID_CHATPANE,
		ID_SEND,
		ID_CTRL_ENTER,
		ID_BUTTON_HISTORY,
		ID_TYPING_TIMER,
		ID_BUTTON_USERINFO,
		ID_CHATPANEL_HIGHEST
	};

private:
	Buddy* buddy;
	AvatarArea* avatarArea;
	iChatLog* log;
	wxRichTextCtrl* input;
	wxStaticText* typingStateText;
	wxStaticText* statusMessageText;
	ChatWindow* cw;
	wxNotebook* nb;
	wxSplitterWindow*  splitView;
	wxBitmapButton* sendButton;
	wxPanel* buttonPane;
	wxBoxSizer* buttonSizer;
	wxTimer* typingNotifyTimer;
	std::map<int, int> msgs;
	db_id lastIncomingMsgHistoryId;
	bool typingNotificationSent;
	time_t lastMessageSent;

public:
	ChatPanel(ChatWindow* cw, wxNotebook* nb, Buddy* buddy);
	virtual ~ChatPanel();

	void initPane();
	void messageIn(MessageEvent & event);
	void messageCallback(MessageCallbackEvent & event);
	void typingNotification(TypingNotificationEvent & event);
	void statusChanged(StatusEvent & event);
	void avatarChanged(AvatarChangedEvent & event);
	void IncomingFile(FileTransfareEvent & event);
	void onInputKey(wxKeyEvent & event);
	void onInputChanged(wxCommandEvent & event);
	void onSend(wxCommandEvent & event);
	void onButton(wxCommandEvent & event);
	void onCtrlEnter(wxCommandEvent & event);
	void onTextTyped(wxTimerEvent & event);
	void doSend();
	void tabChanged();
	void clearUnreadMsgs();

	bool sendTypingNotifications();
	Buddy* getBuddy();

private:
	void addButton(const wxString & name, wxBitmap* icon, wxWindowID id);
	void scrollToEnd();
	void OnURL(wxTextUrlEvent& event);

private:
	DECLARE_EVENT_TABLE()

};

}

#endif /*CHATPANEL_H_*/
